<?php
declare (strict_types = 1);

namespace app\admin\model\project;

use bbweb\traits\ModelTrait;
use bbweb\basic\BaseModel;
use think\facade\Session;

/**
 * @mixin \think\Model
 */
class ProjectTaskJobs extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'project_task_jobs';

    use ModelTrait;


    // 设置字段信息
    protected $schema = [
        'id'			=> 'int',
        'project_id'    => 'int',
        'task_id'	    => 'int',
        'uid'		    => 'int',
        'user_name'	    => 'varchar',
        'job'	        => 'varchar',
        'create_at'     => 'int',
    ];

    public function getCreateAtAttr($value)
    {
        return date('Y/m/d H:i', $value);
    }

    /**
     * 添加日志
     * @param $uid
     * @param $project_id
     * @param $task_id
     * @param $event_name
     * @param $events
     * @return ProjectTaskLogs|\think\Model
     */
    public static function addJobs($item)
    {
        $adminInfo = Session::get('adminInfo');
        $item['uid'] = $adminInfo['id'];
        $item['user_name'] = $adminInfo['real_name'];
        return self::create($item);
    }
}
